<%@page import="java.text.ParseException"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="java.io.*,java.io.File,java.io.FileInputStream,java.io.InputStream,java.sql.*,java.util.*,org.apache.commons.io.*,org.apache.commons.logging.*" %>
<%@page import="com.mysql.jdbc.Driver,org.apache.poi.hwpf.extractor.WordExtractor" %>
<%@ page import="com.ucap.system.db.*,oracle.jdbc.driver.OracleDriver"%>
<%@page import="java.io.*,java.util.*,java.sql.*,org.apache.commons.io.FileUtils,org.apache.commons.logging.Log,org.apache.commons.logging.LogFactory" %>
<%@page import="com.ucap.base.model.*,com.ucap.migration.*,com.ucap.utils.*" %>
<%@page import="java.util.Date,java.text.SimpleDateFormat,com.ucap.migration.manuscript.*" %>
<%@page import="com.ucap.migration.resource.*,com.ucap.base.model.wcm.Manuscript" %>
<%@page import="com.ucap.migration.helper.LoadObjectSupport,org.apache.poi.POIXMLDocument"%>
<%@page import="javax.servlet.ServletResponse,javax.servlet.ServletRequest,javax.servlet.ServletException,javax.servlet.http.HttpServlet,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse"%>

<%
	try{
    request.setCharacterEncoding("utf-8");
    final String channelId = "b3ca57b34b8940d9888dc76b9694941d";//临时栏目ID
// 	String SYH_ = "";//生成规则
	final String website = "89221d5df93146ba9d145c805a4fcb73";
//     String syh = getParameter(request,"syh");// rs.getString("syh");
    String title = getParameter(request,"title");//非空
    String content = getParameter(request,"content");//非空
    String time = getParameter(request,"time");//非空
    String wh = getParameter(request,"wh");//rs.getString("wh");
    String syh = getParameter(request,"syh");
    String nrgs = getParameter(request,"nrgs");//rs.getString("nrgs");
    String zrz = getParameter(request,"zrz");//rs.getString("zrz");

	long put_time = toDate("yyyy-MM-dd HH:mm:ss",time).getTime();

    boolean flag = false;
    boolean result = false;
    String import_opt_user_id = "administrator";
    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
    Manuscript manuscript = null;
    String memo = "摘要";

    /*
     * 新建测试文章类，并设置参数
     * 
     */
    manuscript = new Manuscript();

    //获取文章Id
    String infoId = generateString32();
    manuscript.setManuscriptId(infoId);
    manuscript.setChannelId(channelId);
    manuscript.setTitle(title);// 去掉title空格
    manuscript.setType("0");// 这里的type为1时可能出现稿件生成静态页正文出不来，显示为图片
    manuscript.setStatus("1");// 这里的type直接为3（已签发）时可能出现稿件静态页不生成。
    //manuscript.setKeyword("关键字");
    manuscript.setKeyword("");
    //			Date ddx = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
//     long createTime11 = //TimeUtil.dateStrToGMTLong(cwrq + " 00:00:00","GMT+8:00");
//     long pubTime11 = //TimeUtil.dateStrToGMTLong(fbrq + " 00:00:00","GMT+8:00");
    String sql = "insert into cms_manuscript_metadata_g values('"
            + infoId + "','" + syh + "','','','','" + title + "','"
            + wh + "','" + nrgs + "'," + put_time + ",'" + zrz
            + "'," + put_time + ",'','','','','','','','','','')";
    
    com.ucap.system.db.DataBase database = DataBaseFactory.getDataBase(0);
    database.execUpdate(sql);
	if(database!=null){database.close();}//关闭连接
	
    manuscript.setCreatedTime(put_time);
    manuscript.setPublishedTime(put_time);
    manuscript.setIsDisplayContent("0");
    manuscript.setIsSticky("0");
    manuscript.setCreatorId(import_opt_user_id);

    manuscript.setIsModifiedSeqNum("0");
    manuscript.setSortedTime(0l);
    manuscript.setIsEncrypted("0");
    manuscript.setIsPageBreak("0");
    manuscript.setSeqNum(System.currentTimeMillis());
    manuscript.setModifiedTime(System.currentTimeMillis());
    manuscript.setMemo(memo);
    manuscript.setUrl(sf.format(new Date(put_time)));

    if (!manuscript.getUrl().endsWith(".shtml")) {// 新增稿件
        manuscript.setUrl(manuscript.getUrl() + "/"
                + manuscript.getManuscriptId() + ".shtml");// 生成稿件URL
    }
    try {
        LoadObjectSupport dd = new LoadObjectSupport();
    } catch (Exception e) {
        
    }
    com.ucap.migration.manuscript.ManuscriptService manuscriptService = new com.ucap.migration.manuscript.ManuscriptService();
    com.ucap.migration.resource.ResourceTextHandle resourceTextHandle = new com.ucap.migration.resource.ResourceTextHandle();
    try {
        //写入目的数据库
        resourceTextHandle.saveText(manuscript, content);
        result = manuscriptService.saveManuscript(manuscript);
    } catch (Exception e) {
        e.printStackTrace();
        out.print(e.getMessage());
    }
}catch(Exception e){
    
}
%>
<%!
private String getParameter(HttpServletRequest request,String name){
    String val = request.getParameter(name);
    if(null!=val && !"".equals(val)){
        return val;
    }
    return "";
} 

private boolean nullOrEmpty(String str){
    if(null!=str && !"".equals(str)){
        return false;
    }
    return true;
}

private Date toDate(String format, String strDate) throws ParseException {
	SimpleDateFormat sdf = new SimpleDateFormat(format);
	return sdf.parse(strDate);
}


private String fotmatTime(Date d,String format) {
	SimpleDateFormat sdf = new SimpleDateFormat(format);
	return sdf.format(d);
} 

private String generateString32() {
	String radStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	StringBuffer generateRandStr = new StringBuffer();
	Random rand = new Random();
	int length = 32;
	for (int i = 0; i < length; i++) {
		int randNum = rand.nextInt(36);
		generateRandStr.append(radStr.substring(randNum, randNum + 1));
	}
	return generateRandStr + "";
}
%>